#include <stdio.h>
#include <stdlib.h>

/*Joseph Conrad Stack
* csc253
* jcstack
*
* reads digit in first position of input file and skips the rest
* sums all elligable digits together
*/


int main(){
    FILE* dataFile=NULL;
    int value=0;
    int i=0;
    int total = 0;
    int temp = 0;

    if((dataFile=fopen("IN.DAT","r"))==NULL){
        printf("IN.DAT does not exist\n");
        return EXIT_FAILURE;
    }

    while((value=fgetc(dataFile)) != EOF) {
        if(isdigit(value)){
            ungetc(value,dataFile);
            if((i=fscanf(dataFile,"%d",&temp)) == 1){
           
                total += temp;
            }

            while((value=fgetc(dataFile))!= '\n'){
            }
            /* cycle through till the end of the line */
         
        }else{
            while((value=fgetc(dataFile))!= '\n'){
            }
            /* cycle through till the end of the line */
        }
      
    }
    printf("\nThe sum of the input is: %d\n", total);
    fclose(dataFile);
    return EXIT_SUCCESS;
}
